import { ElMessage, ElMessageBox } from 'element-plus'

export default () => {
    // 二进制数据导出xlsx
    const deriveXlsx = res => {
        const blob = new Blob([res], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' })
        const link = document.createElement('a')
        link.href = window.URL.createObjectURL(blob)
        link.download = '导出数据.xlsx' // 你想要的文件名
        link.click()
        window.URL.revokeObjectURL(link.href)
    }

    // 删除功能 && 确认删除框
    const delPointOutFn = (ids, delFn, listFn) => {
        ElMessageBox.confirm(
            `是否确认删除线索编号为"${ids}"的数据项?`,
            '系统提示',
            {
                cancelButtonText: '取消',
                confirmButtonText: '确定',
                type: 'warning',
            }
        ).then(async () => {
            try {
                await delFn(ids)
                listFn()
                ElMessage.success('删除成功')
            } catch (err) {
                ElMessage.error('删除失败')
            }
        }).catch(() => { })
    }

    return {
        deriveXlsx,
        delPointOutFn
    }
}